import Vue from 'vue'
import VueRouter from 'vue-router'
import GoodsCar from '../components/goodsCar.vue'
import details from '../components/details/details.vue'
import Home from '../components/Home.vue'
import ClassAstions from '../components/classActions.vue'
import Orders from '../components/orders/Orders.vue'
import Search from '../components/search/Search.vue'
import Myde from '../components/myde.vue'
import Goods from '../components/goods/Goods.vue'
import Getpople from '../components/details/kefu.vue'
import Login from '../components/Login.vue'
import AddressList from '../components/address/AddressList.vue'
import addressedit from '../components/address/AddressEdit.vue'
Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  { path: '/home', component: Home },
  { path: '/actions', component: ClassAstions },
  { path: '/cars', component: GoodsCar },
  { path: '/details', component: details },
  { path: '/orders', component: Orders },
  { path: '/search', component: Search },
  { path: '/goods', component: Goods },
  { path: '/myde', component: Myde },
  { path: '/getpople', component: Getpople },
  {
    path: '/addressedit',
    component: addressedit
  },
  {
    path: '/addresslist',
    component: AddressList
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
})
export default router
